/*
 * This file is part of the <a href="http://code.google.com/p/pux">PUX Framework</a>
 *
 * Copyright 2008 by <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package de.teamskill.pux.library.image;

import java.awt.image.BufferedImage;

import de.teamskill.pux.engine.InputPort;

/**
 * ThresholdNode
 * 
 * @author <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 * 
 */
public class ThresholdNode extends AbstractImageFilter {

	/**
	 * min
	 */
	private InputPort min;

	/**
	 * max
	 */
	private InputPort max;

	/**
	 * ThresholdNode Constructor
	 * 
	 */
	public ThresholdNode() {
		this("THRESHOLD" + nr++, false);
	}

	/**
	 * ThresholdNode Constructor
	 * 
	 * @param nodeName
	 * @param continuous
	 */
	public ThresholdNode(String nodeName, boolean continuous) {
		super(nodeName, continuous);
	}

	/**
	 * @see de.teamskill.pux.engine.AbstractNode#compute()
	 */
	public void compute() {
		BufferedImage ci = (BufferedImage) in.fetchData();

		int t1 = (Integer) min.fetchData();
		int t2 = (Integer) max.fetchData();

		LOG_NODE.fine("Performing threshold (" + t1 + ":" + t2 + ") on image data for " + ci.getWidth() + "x"
				+ ci.getHeight() + " pixels.");

		BufferedImage gi = new BufferedImage(ci.getColorModel(), ci.getRaster(), false, null);

		// TODO implement threshold operation

		out.pushData(gi);
	}

	/**
	 * @see de.teamskill.pux.library.image.AbstractImageFilter#createPorts()
	 */
	protected void createPorts() {
		super.createPorts();
		min = addConfigurationPort("min", Integer.class, new Integer(64));
		max = addConfigurationPort("max", Integer.class, new Integer(192));
	}

}
